<?php

	function remove_wpautop($content) { 
		$content = do_shortcode( shortcode_unautop($content) ); 
		$content = preg_replace( '#^<\/p>|^<br \/>|<p>$#', '', $content );
		return $content;
	}


//COLUMNS SHORTCODES	
	function one_half( $atts, $content = null ) { return '<div class="one_half">'.do_shortcode($content).'</div>'; }
	add_shortcode('one_half', 'one_half');
	
	function one_third( $atts, $content = null ) { return '<div class="one_third">'.do_shortcode($content).'</div>'; }
	add_shortcode('one_third', 'one_third');
	
	function one_forth( $atts, $content = null ) { return '<div class="one_forth">'.do_shortcode($content).'</div>'; }
	add_shortcode('one_forth', 'one_forth');	
	
	function two_thirds( $atts, $content = null ) { return '<div class="two_thirds">'.do_shortcode($content).'</div>'; }
	add_shortcode('two_thirds', 'two_thirds');
	
	function three_forths( $atts, $content = null ) { return '<div class="three_forths">'.do_shortcode($content).'</div>'; }
	add_shortcode('three_forths', 'three_forths');	
	
	function one_half_last( $atts, $content = null ) { return '<div class="one_half_last">'.do_shortcode($content).'</div>'; }
	add_shortcode('one_half_last', 'one_half_last');
	
	function one_third_last( $atts, $content = null ) { return '<div class="one_third_last">'.do_shortcode($content).'</div>'; }
	add_shortcode('one_third_last', 'one_third_last');
	
	function one_forth_last( $atts, $content = null ) { return '<div class="one_forth_last">'.do_shortcode($content).'</div>'; }
	add_shortcode('one_forth_last', 'one_forth_last');	
	
	function two_thirds_last( $atts, $content = null ) { return '<div class="two_thirds_last">'.do_shortcode($content).'</div>'; }
	add_shortcode('two_thirds_last', 'two_thirds_last');
	
	function three_forths_last( $atts, $content = null ) { return '<div class="three_forths_last">'.do_shortcode($content).'</div>'; }
	add_shortcode('three_forths_last', 'three_forths_last');
	
	function horizontal_separator( $atts, $content = null ) { return '<div class="content_horizontal_separator">'.do_shortcode($content).'</div>'; }
	add_shortcode('horizontal_separator', 'horizontal_separator');
	
	function break_line( $atts, $content = null ) { return '<div class="content_horizontal_separator_break">'.do_shortcode($content).'</div>'; }
	add_shortcode('break_line', 'break_line');
	
	function highlight( $atts, $content = null ) { return '<span class="content_highlight">'.do_shortcode($content).'</span>'; }
	add_shortcode('highlight', 'highlight');
	
	function quote_left( $atts, $content = null ) { return '<span class="shortcode_quote_left">'.do_shortcode($content).'</span>'; }
	add_shortcode('quote_left', 'quote_left');
	
	function quote_right( $atts, $content = null ) { return '<span class="shortcode_quote_right">'.do_shortcode($content).'</span>'; }
	add_shortcode('quote_right', 'quote_right');
	
	function big_quote( $atts, $content = null ) { return '<div class="shortcode_big_quote">'.do_shortcode($content).'</div>'; }
	add_shortcode('big_quote', 'big_quote');
	
	
	
	function heading( $atts, $content = null ) {
    extract(shortcode_atts(array(
		  "size" => '1'
		), $atts));		
	   return '<h'.$size.'>'.$content.'</h'.$size.'>';
	}
	add_shortcode('heading', 'heading');
	
	function intro( $atts, $content = null ) { return '<div class="content_intro">'.do_shortcode($content).'</div>'; }
	add_shortcode('intro', 'intro');
	
	function framed( $atts, $content = null ) { return '<div class="framed_content">'.do_shortcode($content).'</div>'; }
	add_shortcode('framed', 'framed');
	
	
	// IMAGE FRAME
	function image_frame( $atts, $content = null )
	{
		extract(shortcode_atts(array(
			"width" => '200',										 
			"height" => '200',
			"align" => 'none',
			"pattern" => 'dotted',
			"alt" => 'picture',
			"description" => ''
		), $atts));
		
		$width = str_replace('px', '' ,$width);
		$height = str_replace('px', '' ,$height);	
		$class = '';
		$margin = '';
		
		$link_title = '';
		$link_title = $description;
		
		if ( $alt == '' )
		{
			$alt = 'picture';	
		}
		
		switch($align)
		{
			case 'none': $class = ''; break;
			case 'left':
				$class = 'image_frame_align_left'; 
				$margin = 'margin: 0px 15px 15px 0px;';
				break;
			case 'right':
				$class = 'image_frame_align_right'; 
				$margin = 'margin: 0px 0px 15px 15px;';
				break;			
		}
		
		switch($pattern)
		{
			case 'dotted': $pattern = ' image_frame_dotted_pattern'; break;
			case 'exterior_line': $pattern = ' image_frame_exterior_line'; break;	
		}		
		
		
		$thumbnail_size = 'w='.$width.'&amp;h='.$height;
		$image_source = get_template_directory_uri().'/includes/timthumb.php?src='.$content.'&amp;'.$thumbnail_size.'&amp;zc=1&amp;q=100';
		
		$framed_image = '<a title="'.$link_title.'" rel="prettyPhoto"; style="width: '.$width.'px; height: '.$height.'px; '.$margin.'" class="image_frame '.$class.$pattern.'" href="'.$content.'">';
			$framed_image .= '<img style="width: '.$width.'px; height: '.$height.'px;" src="'.$image_source.'" alt="'.$alt.'"/>';
		$framed_image .= '</a>';
		
		return $framed_image;
	}
	add_shortcode('image_frame', 'image_frame');
	
	// SLIDESHOW
	function slideshow( $atts, $content = null )
		{
			extract(shortcode_atts(array(
				  "width" => '630',										 
				  "height" => '350',
				  "effect" => 'random'
				), $atts));	
			$width = str_replace('px', '', $width);
			$height = str_replace('px', '', $height);	
			
			$timthumb_url = get_template_directory_uri().'/includes/timthumb.php';
			
			$content = trim($content);
			$images = explode(',',$content);
			
			$random = rand(0,999999);
			$random_letter = rand(97, 122);
			$random .= chr($random_letter);
			
			$slideshow_shortcode = '<script type="text/javascript">';
				$slideshow_shortcode .= 'jQuery(window).load(function() {';
					$slideshow_shortcode .= 'jQuery("#slider-'.$random.'").nivoSlider({controlNav:true,manualAdvance:true, directionNavHide:false, effect:\''.$effect.'\'});';
				$slideshow_shortcode .= '});';
			$slideshow_shortcode .= '</script>';
			$slideshow_shortcode .= '<div id="slider-'.$random.'" style="width:'.$width.'px; height:'.$height.'px;">';
				foreach($images as $image) 
				{
					$image = str_replace(' ', '' ,$image);
					$thumbnail_size = 'w='.$width.'&amp;h='.$height;
					$image_source = $timthumb_url.'?src='.$image.'&amp;'.$thumbnail_size.'&amp;zc=1&amp;q=100';
					$slideshow_shortcode .= '<img src="'.$image_source.'" />';
				}
			$slideshow_shortcode .= '</div>';
			
			$slideshow_shortcode .= '<div class="nivo_small_thumbnails slideshow_shortcode" style="width:'.$width.'px;">';
				foreach($images as $key => $image) 
					$slideshow_shortcode .= '<a rel="'.$key.'" >'.$key.'</a>';
			$slideshow_shortcode .= '</div>';
			
			return $slideshow_shortcode;
		}
		add_shortcode('slideshow', 'slideshow');
	
	// TOGGLES
	function toggles( $atts, $content = null )
	{
		$toggles = explode('toggle_separator', $content);

		$toggle_return = '<div class="toggles">';
			foreach($toggles as $toggle) 
			{
				$toggle_title  = explode('toggle_title=', $toggle);
				$toggle_title  = explode('toggle_content=', $toggle_title[1]);
				$toggle_content = explode('toggle_content=', $toggle);
				
				$toggle_return .= '<div class="one_toggle">';
					$toggle_return .= '<div class="toggle_header clearfix">';
						$toggle_return .= '<div class="cross"></div>';
						$toggle_return .= '<div class="header_content">';
							$toggle_return .= $toggle_title[0];
						$toggle_return .= '</div>';
					$toggle_return .= '</div>';
					$toggle_return .= '<div class="toggle_content">';
						$toggle_return .= $toggle_content[1];
					$toggle_return .= '</div>';
				$toggle_return .= '</div>';
			}
		$toggle_return .= '</div>';
		
		return $toggle_return;
	}
	add_shortcode('toggles', 'toggles');
	
	
	
	function tabs( $atts, $content = null )
	{
		$toggles = explode('tabs_separator', $content);


		
		$toggle_return = '<div class="toggles">';
			foreach($toggles as $toggle) 
			{
				$toggle_title  = explode('toggle_title=', $toggle);
				$toggle_title  = explode('toggle_content=', $toggle_title[1]);
				$toggle_content = explode('toggle_content=', $toggle);
				
				$toggle_return .= '<div class="one_toggle">';
					$toggle_return .= '<div class="toggle_header clearfix">';
						$toggle_return .= '<div class="cross"></div>';
						$toggle_return .= '<div class="header_content">';
							$toggle_return .= $toggle_title[0];
						$toggle_return .= '</div>';
					$toggle_return .= '</div>';
					$toggle_return .= '<div class="toggle_content">';
						$toggle_return .= $toggle_content[1];
					$toggle_return .= '</div>';
				$toggle_return .= '</div>';
			}
		$toggle_return .= '</div>';
		
		return $tabs_return;
	}
	add_shortcode('tabs', 'tabs');	
	
	function arrow_list( $atts, $content = null ) {
		return str_replace('<ul>', '<ul class="arrow_list">', remove_wpautop($content));
	}
	add_shortcode('arrow_list', 'arrow_list');
	
	function bullet_list( $atts, $content = null ) {
		return str_replace('<ul>', '<ul class="bullet_list">', remove_wpautop($content));
	}
	add_shortcode('bullet_list', 'bullet_list');
	
	function plus_list( $atts, $content = null ) {
		return str_replace('<ul>', '<ul class="plus_list">', remove_wpautop($content));
	}
	add_shortcode('plus_list', 'plus_list');
	
	function minus_list( $atts, $content = null ) {
		return str_replace('<ul>', '<ul class="minus_list">', remove_wpautop($content));
	}
	add_shortcode('minus_list', 'minus_list');
	
	function square_list( $atts, $content = null ) {
		return str_replace('<ul>', '<ul class="square_list">', remove_wpautop($content));
	}
	add_shortcode('square_list', 'square_list');
	
	function heart_list( $atts, $content = null ) {
		return str_replace('<ul>', '<ul class="heart_list">', remove_wpautop($content));
	}
	add_shortcode('heart_list', 'heart_list');
	
	function diamond_list( $atts, $content = null ) {
		return str_replace('<ul>', '<ul class="diamond_list">', remove_wpautop($content));
	}
	add_shortcode('diamond_list', 'diamond_list');
	
	function star_list( $atts, $content = null ) {
		return str_replace('<ul>', '<ul class="star_list">', remove_wpautop($content));
	}
	add_shortcode('star_list', 'star_list');
	
	function check_list( $atts, $content = null ) {
		return str_replace('<ul>', '<ul class="check_list">', remove_wpautop($content));
	}
	add_shortcode('check_list', 'check_list');

	
	// EMBEDED 
	
	function embeded( $atts, $content = null )
	{
		extract(shortcode_atts(array(
			  "width" => '960',										 
			  "height" => '600',
			  "source" => '',
			  "host" => 'youtube'
			), $atts));	
		return '<div class="video_player" style="width: '.$width.'px; height: '.$height.'px;">'.do_shortcode($content).'</div>';
	}
	add_shortcode('embeded', 'embeded');


	// VIDEO PLAYER
	function video_player( $atts, $content = null )
	{
		extract(shortcode_atts(array(
			  "width" => '960',										 
			  "height" => '600',
			  "source" => '',
			  "host" => 'youtube'
			), $atts));	
		
		$search_video = true;
		
		$video_found = stristr($source, 'http://www.youtube.com/watch?v=');
		if ( $video_found != false )
		{
			$video_type = 'youtube';
			$source = str_replace('http://www.youtube.com/watch?v=', '', $source);
			$search_video = false;
			
			$useless_source = strrpos($source, '&');
			if ( $useless_source > 0 ) $source = substr($source, 0, $useless_source);		
		}
		
		if ( $search_video )
		{
			$video_found = stristr($source, 'http://youtu.be/watch?v=');
			if ( $video_found != false )
			{
				$video_type = 'youtube';
				$source = str_replace('http://youtu.be/watch?v=', '', $source);
				$search_video = false;
				
				$useless_source = strrpos($source, '&');
				if ( $useless_source > 0 ) $source = substr($source, 0, $useless_source);		
			}	
		}
		
		if ( $search_video )
		{
			$video_found = stristr($source, 'http://youtube.com/watch?v=');
			if ( $video_found != false )
			{
				$video_type = 'youtube';
				$source = str_replace('http://youtube.com/watch?v=', '', $source);
				$search_video = false;
				
				$useless_source = strrpos($source, '&');
				if ( $useless_source > 0 ) $source = substr($source, 0, $useless_source);		
			}	
		}
		
		if ( $search_video )
		{
			$video_found = stristr($source, 'http://www.vimeo.com/');
			if ( $video_found != false )
			{
				$video_type = 'vimeo';
				$source = str_replace('http://www.vimeo.com/', '', $source);
				$search_video = false;
			}		
		}
		
		if ( $search_video )
		{
			$video_found = stristr($source, 'http://vimeo.com/');
			if ( $video_found != false )
			{
				$video_type = 'vimeo';
				$source = str_replace('http://vimeo.com/', '', $source);
				$search_video = false;
			}		
		}
		
		if ( $video_type == 'youtube' )
		{
			$video = '<div class="video_player" style="width: '.$width.'px; height: '.$height.'px;">';
				$video .= '<iframe width="'.$width.'" height="'.$height.'" src="http://www.youtube.com/embed/'.$source.'?hd=1&amp;wmode=transparent" frameborder="0" allowfullscreen></iframe>';
			$video .= '</div>';
		}
		
		if ( $video_type == 'vimeo' )
		{
			$video = '<div class="video_player" style="width: '.$width.'px; height: '.$height.'px;">';
				$video .= '<iframe src="http://player.vimeo.com/video/'.$source.'?title=0&amp;byline=0&amp;portrait=0&amp;wmode=transparent" width="'.$width.'" height="'.$height.'" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
			$video .= '</div>';
		}
		
		return $video;
	}
	
	add_shortcode('video_player', 'video_player');	
	
	
	// BUTTON SHORTCODES
	function button( $atts, $content = null )
	{
		extract(shortcode_atts(array(
			  "url" => '#',										 
			  "text" => 'Button',
			  "type" => ''
			), $atts));		
		
		$button_class  = '';
		$button_rel    = '';
		$add_span_icon = '';
		
		if ($type == '') $type = 'simple';
		
		switch($type)
		{
			case 'simple': 
				$button_class = ' button_simple';
			break;
			
			case 'pdf': 
				$button_class = ' button_pdf';
			break;			
			
			case 'photo': 
				$button_class = ' button_photo';
			break;	
			
			case 'video': 
				$button_class = ' button_video';
				$url = 'mailto:'.$url;
			break;		
			
			case 'music':
				$button_class = ' button_music';				
				$button_rel = ' rel="single-modal "';
			break;		
			
			case 'download': 
				$button_class = ' button_download';
			break;	
		}
		
		if ($type != 'simple')
		{
			$add_span_icon = '<span class="normal"></span>';
			$button_class .= ' button_with_icon';
		}
		
		return '<a href="'.$url.'"'.$button_rel.' class="shortcode_button'.$button_class.'">'.$add_span_icon.$content.'</a>';
	}
	add_shortcode('button', 'button');	


?>